package com.asohofrucol.dto.util;

import com.asohofrucol.dto.ForestResourceRegisterDTO;
import com.asohofrucol.model.ComboValue;
import com.asohofrucol.model.ForestResource;
import com.asohofrucol.model.Ruat;

public class ForestResourceHelperDto {

	public static ForestResourceRegisterDTO convertToRegisterDTO(
			ForestResource ag) {
		ForestResourceRegisterDTO agDTO = new ForestResourceRegisterDTO();
		agDTO.setAssistanceEntity(ag.getAssistanceEntity());
		agDTO.setAssistanceProgram(ag.getAssistanceProgram());
		agDTO.setAverageSalesPrice(ag.getAverageSalesPrice());
		agDTO.setCertifiedSeed((ag.getComboValueCertifiedSeed() != null) ? ag
				.getComboValueCertifiedSeed().getId() : null);
		agDTO.setCultivatedArea(ag.getCultivatedArea());
		agDTO.setEstablishmentCosts(ag.getEstablishmentCosts());
		agDTO.setId(ag.getId());
		agDTO.setMembershipTechnicalAssistancePrograms((ag
				.getComboValueMembershipTechnicalAssistancePrograms() != null) ? ag
				.getComboValueMembershipTechnicalAssistancePrograms().getId()
				: 2L);
		agDTO.setMethodOfPayment((ag.getComboValueMethodOfPayment() != null) ? ag
				.getComboValueMethodOfPayment().getId() : null);
		agDTO.setModifiedDate(ag.getModifiedDate());
		agDTO.setModifierUser(ag.getModifierUser());
		agDTO.setNumberOfTreesProduced(ag.getNumberOfTreesProduced());
		agDTO.setProduct((ag.getComboValueProduct() != null) ? ag
				.getComboValueProduct().getId() : null);
		agDTO.setProductionForTheMarket(ag.getProductionForTheMarket());
		agDTO.setProductOther(ag.getProductOther());
		agDTO.setRuatId(ag.getRuat().getId());
		agDTO.setSaleType((ag.getComboValueSaleType() != null) ? ag
				.getComboValueSaleType().getId() : null);
		agDTO.setSellsToNameAndSurname(ag.getSellsToNameAndSurname());
		agDTO.setSiteForSale((ag.getComboValueSiteForSale() != null) ? ag
				.getComboValueSiteForSale().getId() : null);
		agDTO.setStatus(ag.getStatus());
		agDTO.setSubProductCrop(ag.getSubProductCrop());
		agDTO.setSubProductUse(ag.getSubProductUse());
		agDTO.setSustenanceCost(ag.getSustenanceCost());
		agDTO.setVariety(ag.getVariety());
		agDTO.setYieldPerTree(ag.getYieldPerTree());
		agDTO.setProductDesc(ag.getComboValueProduct().getDescription());

		return agDTO;
	}

	public static ForestResource converRegisterToEntity(
			ForestResourceRegisterDTO agDTO) {
		ForestResource ag = new ForestResource();
		ag.setAssistanceEntity(agDTO.getAssistanceEntity());
		ag.setAssistanceProgram(agDTO.getAssistanceProgram());
		ag.setAverageSalesPrice(agDTO.getAverageSalesPrice());
		ag.setComboValueCertifiedSeed(new ComboValue(agDTO.getCertifiedSeed()));
		ag.setComboValueMembershipTechnicalAssistancePrograms(new ComboValue(
				agDTO.getMembershipTechnicalAssistancePrograms()));
		ag.setComboValueMethodOfPayment(new ComboValue(agDTO
				.getMethodOfPayment()));
		ag.setComboValueProduct(new ComboValue(agDTO.getProduct()));
		ag.setComboValueSaleType(new ComboValue(agDTO.getSaleType()));
		ag.setComboValueSiteForSale(new ComboValue(agDTO.getSiteForSale()));
		ag.setCultivatedArea(agDTO.getCultivatedArea());
		ag.setEstablishmentCosts(agDTO.getEstablishmentCosts());
		ag.setId(agDTO.getId());
		ag.setModifiedDate(agDTO.getModifiedDate());
		ag.setModifierUser(agDTO.getModifierUser());
		ag.setNumberOfTreesProduced(agDTO.getNumberOfTreesProduced());
		ag.setProductionForTheMarket(agDTO.getProductionForTheMarket());
		ag.setProductOther(agDTO.getProductOther());
		ag.setRuat(new Ruat(agDTO.getRuatId()));
		ag.setSellsToNameAndSurname(agDTO.getSellsToNameAndSurname());
		ag.setStatus(agDTO.getStatus());
		ag.setSubProductCrop(agDTO.getSubProductCrop());
		ag.setSubProductUse(agDTO.getSubProductUse());
		ag.setSustenanceCost(agDTO.getSustenanceCost());
		ag.setVariety(agDTO.getVariety());
		ag.setYieldPerTree(agDTO.getYieldPerTree());
		return ag;
	}

	@SuppressWarnings("finally")
	public static boolean isNumber(String a){
		boolean resp = false;
		try{
			Long.parseLong(a);
			resp=true;
		}
		catch(Exception e){
			resp=false;
		}
		finally{
			return resp;
		}

	}
}
